package com.mm.controller;

import com.mm.bo.*;
import com.mm.exception.CustomException;
import com.mm.pojo.DepartmentInfo;
import com.mm.service.DepartmentInfoService;
import com.mm.util.GetHeadUtil;
import com.mm.util.PageUtil;
import com.mm.util.ResultUtil;
import com.mm.vo.DepastaffVo;
import com.mm.vo.EmpPunishListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.record.BOFRecord;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 林友航
 * @version 1.0
 * @date 2020/12/4 10:53
 */

@Api(value = "部门管理", tags = "用于部门管理的相关接口")
@RestController
public class DepartmentInfoController {
    @Resource
    private DepartmentInfoService departmentInfoService;

    @ApiOperation(value = "部门人员管理筛选查询", notes = "查询条件(工号、姓名、入职时间、部门)", httpMethod = "POST")
    @PostMapping("/v1/department/selectDepartment")
    public ResultUtil<Object> selectDepartment(@RequestBody @Valid DepartmentSearchBo departmentSearchBo) {
        PageUtil<DepastaffVo> pageUtil = departmentInfoService.selectDepartmentInfo(departmentSearchBo);
        return ResultUtil.success(pageUtil);
    }

    @ApiOperation(value = "添加部门信息", notes = "添加部门信息", httpMethod = "POST")
    @PostMapping("/v1/department/insertDepaInfo")
    public ResultUtil<Object> insertDepaInfo(@RequestBody @Valid InserDepaInfoBo inserDepaInfoBo) throws Exception {
        inserDepaInfoBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = departmentInfoService.insertDepaInfo(inserDepaInfoBo);
        if (row < 1) {
            throw new CustomException("添加部门信息失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "查询部门列表", notes = "查询部门列表", httpMethod = "GET")
    @GetMapping("/v1/department/queryDepaList")
    public ResultUtil<Object> queryDepaList() {
        List<DepartmentInfo> departmentInfos = departmentInfoService.queryDepaList();
        return ResultUtil.success(departmentInfos);
    }

    @ApiOperation(value = "修改部门信息", notes = "修改部门信息", httpMethod = "POST")
    @PostMapping("/v1/department/updateDepaInfo")
    public ResultUtil<Object> updateDepaInfo(@RequestBody @Valid DepaUpdateBo depaUpdateBo) throws Exception {
        depaUpdateBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = departmentInfoService.updateDepaInfo(depaUpdateBo);
        if (row < 1) {
            throw new CustomException("修改部门信息失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "删除部门信息", notes = "删除部门信息", httpMethod = "GET")
    @GetMapping("/v1/department/deleteDepaInfo/{depaId}")
    public ResultUtil<Object> deleteDepaInfo(@PathVariable("depaId") String depaId) {
        Integer row = departmentInfoService.deleteDepaInfo(depaId, GetHeadUtil.getHeadToken());
        if (row < 1) {
            throw new CustomException("删除部门信息失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "添加员工考核评价", notes = "添加员工考核评价", httpMethod = "POST")
    @PostMapping("/v1/department/evaluationEmpInfo")
    public ResultUtil<Object> evaluationEmpInfo(@RequestBody @Valid EvaluationEmpInfoBo evaluationEmpInfoBo) throws Exception {
        evaluationEmpInfoBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = departmentInfoService.evaluationEmpInfo(evaluationEmpInfoBo);
        if (row < 1) {
            throw new CustomException("添加员工考核评价失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "添加员工处罚", notes = "添加员工处罚", httpMethod = "POST")
    @PostMapping("/v1/department/punishEmpInfo")
    public ResultUtil<Object> punishEmpInfo(@RequestBody @Valid PunishEmpInfoBo punishEmpInfoBo) throws Exception {
        punishEmpInfoBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = departmentInfoService.punishEmpInfo(punishEmpInfoBo);
        if (row < 1) {
            throw new CustomException("添加员工处罚失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "查询员工处罚列表", notes = "查询员工处罚列表", httpMethod = "POST")
    @PostMapping("/v1/department/queryEmpPunishList")
    public ResultUtil<Object> queryEmpPunishList(@RequestBody @Valid EmpPunishListBo empPunishListBo) {
        PageUtil<EmpPunishListVo> empPunishListVoPageUtil = departmentInfoService.queryEmpPunishList(empPunishListBo);
        return ResultUtil.success(empPunishListVoPageUtil);
    }


}
